#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author   : BUZAI
# @Time     : 2021/7/16 14:25
from setting import *

def set_case_flie():
    template=os.path.join(BASE_PATH,'case_template.txt')
    file=os.listdir(DATA_PATH)   #取出data目录下的所有文件
    for fli in file:
        if fli.endswith('.yaml') or fli.endswith('.yml'):
            #测试用例文件名和yaml文件名
            test_data=fli.replace('.yaml','').replace('.yml','')
            #测试用例名
            test_class=test_data.title().replace('_','')
            #测试方法名
            test_method=test_data.lower()
            with open(template,'r',encoding='utf-8') as temp:
                #从模板中取出内容
                content=temp.read()%{
                    'class_name':test_class,
                    'method_name':test_method,
                    'data_name':test_data
                }
            test_xiaobai_file='test_xiaobai_%s.py'%test_data
            #根据模板生成用例文件
            with open(os.path.join(CASES_PATH,test_xiaobai_file),'w',encoding='utf-8') as f:
                f.write(content)

if __name__ == '__main__':
    set_case_flie()